<!-- 体检订单详情 -->
<template>
	<view class="wrapper">
		
		<!-- <view v-if="checkup_package_id == '15'">
			
		</view>
		
		<u-button type="success" text="我的核验码" @click="openQRCode"></u-button>
		
		<u-modal :show="qrShow" :title="'我的核验码'" @confirm="qrShow = false">
			<view class="slot-content">
				<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`}" />
			</view>
		</u-modal> -->
		
		<canvas canvas-id="qrcode" :style="{width: `${qrcodeSize}px`, height: `${qrcodeSize}px`, margin: 'auto'}" />
		
		<div style="margin-top: 15px;"></div>
		<view class="content-wrapper">
			<p style="color: #ff5722;">请提供二维码给现场工作人员进行扫码核验，核验通过后即可领取体检表</p>
		</view>
		<div style="margin-top: 10px;"></div>
		<u-button v-if="detail.ifpay == '1'" type="error" text="退款" @click="refund()"></u-button>
	</view>
</template>

<script>
	import uQRCode from '@/uni_modules/cc-defineQRCode/components/cc-defineQRCode/common/uqrcode.js'
	export default {
		data() {
			return {
				detail: {},
				checkup_package_id: '',
				qrcodeSize: 200,
				// 最终生成的二维码图片
				qrcodeSrc: '',
				qrShow: false,
				orderId: '',
				type: 1
			}
		},
		onLoad(option) {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('detail', (data) => {
				this.detail = data.data
				this.checkup_package_id = this.detail.checkup_package_id
				console.log(this.detail)
			})
			this.orderId = option.orderId
			
			this.openQRCode()
		},
		methods: {
			openQRCode() {
				uni.showLoading({
				    title: '二维码加载中'
				});
				this.qrShow = true
				this.make()
			},
			make() {
				let currentUserCard = uni.getStorageSync('current_user_card')
				let qrcodeText = {
					id: this.orderId,
					copenid: uni.getStorageSync('openid')
				}
				
				console.log(qrcodeText)
			
				uQRCode.make({
					canvasId: 'qrcode',
					text: JSON.stringify(qrcodeText),
					size: this.qrcodeSize,
					margin: 10,
					success: res => {
						this.qrcodeSrc = res
						console.log('qrcodeSrc = ' + this.qrcodeSrc);
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			},
			
			refund() {
				uni.showModal({
					title: '提示',
					content: '确定要退款吗？',
					success: (res) => {
						if (res.confirm) {
							let openid = uni.getStorageSync('openid')
							this.$app._post_form("entry/wxapp/tijian.refundtijian", {
								openid: openid,
								type: this.type,
								id: this.detail.id
							}, (res) => {
								console.log(res)
							})	
						} else if (res.cancel) {
				
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrapper {
		padding: 10px;
		box-sizing: border-box;
		color: #757575;
		
		.content-wrapper {
			border-radius: 6px;
			border: 1px solid #e3e3e3;
			padding: 10px;
			line-height: 25px;
			background-color: #f5f5f5;
			font-size: .9rem;
			color: #757575;
		}
	}
</style>